package com.wavehi.exce1;

import com.wavehi.pojo.Person;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;

import javax.swing.*;
import java.awt.*;
import java.beans.*;
import java.lang.reflect.Method;

/**
 * @Author WaveHi
 * @Date 26/8/2021 上午 10:32
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Test the use of java.beans.BeanInfo
 */
public class BeanInfoDemo {

    @Test
    public void testFirst() throws IntrospectionException {

        //获取内省信息
        BeanInfo beanInfo = Introspector.getBeanInfo(Person.class);

        //获取属性
//        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();

        //获取方法
        MethodDescriptor[] methodDescriptors = beanInfo.getMethodDescriptors();
        for(MethodDescriptor methodDescriptor : methodDescriptors) {

            //获取方法
            Method method = methodDescriptor.getMethod();
            System.out.println(method);

            //获取参数描述符
            ParameterDescriptor[] parameterDescriptors = methodDescriptor.getParameterDescriptors();
            //异常情况处理:方法可能没有参数
            if(parameterDescriptors != null) {
                for(ParameterDescriptor parameterDescriptor : parameterDescriptors) {
                    System.out.println(parameterDescriptor);
                }
            }


        }

        //获取事件描述符
//        EventSetDescriptor[] eventSetDescriptors = beanInfo.getEventSetDescriptors();

        //获取图标
//        Image icon = beanInfo.getIcon(BeanInfo.ICON_COLOR_16x16);
//        System.out.println(icon);

    }

}
